<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns namespaces declared in document</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="simplexmlelement.count.html">« SimpleXMLElement::count</a></li>
      <li style="float: right;"><a href="simplexmlelement.getname.html">SimpleXMLElement::getName »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.simplexmlelement.html">SimpleXMLElement</a></li>
    <li>Returns namespaces declared in document</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="simplexmlelement.getdocnamespaces" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SimpleXMLElement::getDocNamespaces</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SimpleXMLElement::getDocNamespaces</span> &mdash; <span class="dc-title">
   Returns namespaces declared in document
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-simplexmlelement.getdocnamespaces-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SimpleXMLElement::getDocNamespaces</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$recursive</code><span class="initializer"> = <strong><code>false</code></strong></span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$fromRoot</code><span class="initializer"> = <strong><code>true</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Returns namespaces declared in document
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-simplexmlelement.getdocnamespaces-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">recursive</code></dt>

     <dd>

      <p class="para">
       If specified, returns all namespaces declared in parent and child nodes. 
       Otherwise, returns only namespaces declared in root node.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">fromRoot</code></dt>

     <dd>

      <p class="para">
       Allows you to recursively check namespaces under a child node instead of
       from the root of the XML doc.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-simplexmlelement.getdocnamespaces-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The <code class="literal">getDocNamespaces</code> method returns an <span class="type">array</span> 
   of namespace names with their associated URIs.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-simplexmlelement.getdocnamespaces-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5459">
    <p><strong>示例 #1 Get document namespaces</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;XML<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version="1.0"&nbsp;standalone="yes"?&gt;<br />&lt;people&nbsp;xmlns:p="http://example.org/ns"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;p:person&nbsp;id="1"&gt;John&nbsp;Doe&lt;/p:person&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;p:person&nbsp;id="2"&gt;Susie&nbsp;Q.&nbsp;Public&lt;/p:person&gt;<br />&lt;/people&gt;<br /></span><span style="color: #007700">XML;<br />&nbsp;<br /></span><span style="color: #0000BB">$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$namespaces&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDocNamespaces</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$namespaces</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(1) {
   [&quot;p&quot;]=&gt;
   string(21) &quot;http://example.org/ns&quot;
}
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5460">
    <p><strong>示例 #2 Working with multiple namespaces</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;XML<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version="1.0"&nbsp;standalone="yes"?&gt;<br />&lt;people&nbsp;xmlns:p="http://example.org/ns"&nbsp;xmlns:t="http://example.org/test"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;p:person&nbsp;t:id="1"&gt;John&nbsp;Doe&lt;/p:person&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;p:person&nbsp;t:id="2"&nbsp;a:addr="123&nbsp;Street"&nbsp;xmlns:a="http://example.org/addr"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Susie&nbsp;Q.&nbsp;Public<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/p:person&gt;<br />&lt;/people&gt;<br /></span><span style="color: #007700">XML;<br />&nbsp;<br /></span><span style="color: #0000BB">$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$namespaces&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDocNamespaces</span><span style="color: #007700">(</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$namespaces</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
  [&quot;p&quot;]=&gt;
  string(21) &quot;http://example.org/ns&quot;
  [&quot;t&quot;]=&gt;
  string(23) &quot;http://example.org/test&quot;
  [&quot;a&quot;]=&gt;
  string(23) &quot;http://example.org/addr&quot;
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-simplexmlelement.getdocnamespaces-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="simplexmlelement.getnamespaces.html" class="methodname" rel="rdfs-seeAlso">SimpleXMLElement::getNamespaces()</a> - Returns namespaces used in document</span></li>
    <li class="member"><span class="methodname"><a href="simplexmlelement.registerxpathnamespace.html" class="methodname" rel="rdfs-seeAlso">SimpleXMLElement::registerXPathNamespace()</a> - Creates a prefix/ns context for the next XPath query</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>